export function parseTime(time, cFormat) {
    debugger;
    if (arguments.length === 0 || time === null || time === undefined) {
        return null;
    }

    if ((time + '').length === 10) {
        time = +time * 1000
    }


    const format = cFormat || '{y}-{m}-{d} {h}:{i}:{s}';
    let date;
    if (typeof time == 'object') {
        date = time;
    } else {
        date = new Date(parseInt(time));
    }
    const formatObj = {
        y: date.getFullYear(),
        m: date.getMonth() + 1,
        d: date.getDate(),
        h: date.getHours(),
        i: date.getMinutes(),
        s: date.getSeconds(),
        a: date.getDay()
    };
    const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
        let value = formatObj[key];
        if (key === 'a') return ['一', '二', '三', '四', '五', '六', '日'][value - 1];
        if (result.length > 0 && value < 10) {
            value = '0' + value;
        }
        return value || 0;
    });
    return time_str;
}

export function parseDate(time, type) {
    if (type === 'day') {
        return parseTime(time, '{y}-{m}-{d}');
    } else if (type === 'month') {
        return parseTime(time, '{y}-{m}');
    } else {
        return parseTime();
    }
}

export function priceFormat(price) {
    if (isNaN(price)) {
        return price;
    }
    // 分 --> 元
    const fprice = price / 100;
    return fprice.toFixed(2);
}

export function parseOrderStatus(status) {
    return ['待支付', '支付成功', '支付失败', '用户取消', '超时取消'][status];
}

export function parsePayType(payType) {
    return ['支付宝', '微信'][payType];
}

export function parseChannel(channel) {
    if (channel === 'TED') {
        return '泰迪熊';
    } else if (channel === 'WX') {
        return '微信';
    } else if (channel === 'OTHER') {
        return '其他'
    } else if (channel === 'ALL') {
        return '全部渠道'
    }
    return channel;
}

export function fontUrl(resourceId, randId, resourcePath) {
    const host = process.env.FONT_BASE_API ? process.env.FONT_BASE_API : '';
    return host + resourcePath + '/' + resourceId + '?randId=' + randId;
}

export function parseTranscodeStatus(status) {
    return ['转码成功', '等待转码', '转码中', '转码失败'][status];
}

export function parseRole(role) {
    if (role === 'admin') {
        return '超级管理员';
    } else if (role === 'operator') {
        return '运营管理员';
    } else if (role === 'statistics') {
        return '统计管理员';
    } else {
        return '';
    }
}
